package com.ruoyi.web.controller.business.sundry;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.core.JoR;
import com.ruoyi.common.enums.BusinessErrorEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.sundry.domain.JbEvaluationExample;
import com.ruoyi.business.sundry.service.JbEvaluationExampleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跟进计划评论的参考实例 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("跟进计划评论的参考实例")
@RestController
@RequestMapping("/evaluation_example")
public class JbEvaluationExampleController extends BaseController
{
    @Autowired
    private JbEvaluationExampleService service;

    /**
     * 查询跟进计划评论的参考实例列表
     */
    @ApiOperation("查询跟进计划评论的参考实例列表")
    @PreAuthorize("@ss.hasPermi('evaluation_example:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbEvaluationExample jbEvaluationExample)
    {
        LambdaQueryWrapper<JbEvaluationExample> select = new LambdaQueryWrapper<>();
        select.eq(JbEvaluationExample::getEvaluationId, jbEvaluationExample.getEvaluationId());
        IPage<JbEvaluationExample> iPage = service.page(page.b(), select);
        return getDataTable(iPage.getRecords());
    }

    /**
     * 导出跟进计划评论的参考实例列表
     */
    @ApiOperation("导出跟进计划评论的参考实例列表")
    @PreAuthorize("@ss.hasPermi('evaluation_example:export')")
    @Log(title = "跟进计划评论的参考实例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbEvaluationExample jbEvaluationExample)
    {
        LambdaQueryWrapper<JbEvaluationExample> select = new LambdaQueryWrapper<>();
        IPage<JbEvaluationExample> iPage = service.page(page.b(), select);

        List<JbEvaluationExample> list = iPage.getRecords();
        ExcelUtil<JbEvaluationExample> util = new ExcelUtil<JbEvaluationExample>(JbEvaluationExample.class);
        util.exportExcel(response, list, "跟进计划评论的参考实例数据");
    }

    /**
     * 获取跟进计划评论的参考实例详细信息
     */
    @ApiOperation("获取跟进计划评论的参考实例详细信息")
    @PreAuthorize("@ss.hasPermi('evaluation_example:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增跟进计划评论的参考实例
     */
    @ApiOperation("新增跟进计划评论的参考实例")
    @PreAuthorize("@ss.hasPermi('evaluation_example:add')")
    @Log(title = "跟进计划评论的参考实例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult adds(@RequestBody List<JbEvaluationExample> list)
    {
        if (list.size() > 0)
        {
            Long id = list.get(0).getEvaluationId();
            if (StringUtils.isNotNull(id))
                service.deleteByEvaluationId(id);
            else
                return JoR.err(BusinessErrorEnum.MISSING_PARAMETER);
        }
        return toAjax(service.saveBatch(list));
    }

    /**
     * 修改跟进计划评论的参考实例
     */
    @ApiOperation("修改跟进计划评论的参考实例")
    @PreAuthorize("@ss.hasPermi('evaluation_example:edit')")
    @Log(title = "跟进计划评论的参考实例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbEvaluationExample jbEvaluationExample)
    {
        return toAjax(service.updateById(jbEvaluationExample));
    }

    /**
     * 删除跟进计划评论的参考实例
     */
    @ApiOperation("删除跟进计划评论的参考实例")
    @PreAuthorize("@ss.hasPermi('evaluation_example:remove')")
    @Log(title = "跟进计划评论的参考实例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(service.deleteByEvaluationId(id));
    }
}
